package com.zy.web.controller.bs;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zy.entity.bs.Sign;
import com.zy.pojo.query.bs.SignQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.pojo.vos.common.ResultVo;
import com.zy.service.bs.SignService;
import com.zy.web.controller.base.BaseController;
import com.zy.web.utils.ResultUtil;

@RequestMapping({"bs/sign","m/bs/sign"})
@Controller
public class SignController extends BaseController {

	@Autowired
	private SignService signService;

	/**
	 * 分页
 	 * 
 	 * @param signQuery
	 * @param start
	 * @param limit
	 * @return
	 */
	@RequestMapping("pageSign")
	@ResponseBody
	public PageVo pageSign(SignQuery signQuery, Integer start, Integer limit) {
		return this.signService.pageSign(signQuery, start, limit);
	}

	/**
	 * 新增
	 * 
	 * @param sign
	 * @return
	 */
	@RequestMapping(value = "saveSign", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo saveSign(Sign sign) {
		try {
			this.signService.saveSign(sign);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}
	
	/**
	 * 更新
	 * 
	 * @param sign
	 * @return
	 */
	@RequestMapping(value = "updateSign", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo updateSign(Sign sign) {
		try {
			this.signService.updateSign(sign);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "removeSign", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo removeSign(long id) {
		try {
			this.signService.removeSign(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	/**
	 * 恢复
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "recover", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo recover(long id) {
		try {
			this.signService.recover(id);
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

	@RequestMapping(value = "sign", method = RequestMethod.POST)
	@ResponseBody
	public ResultVo sign() {
		try {
			this.signService.sign(this.getCurrentUser().getId());
			return ResultUtil.success();
		} catch (Exception e) {
			return ResultUtil.error(log, e);
		}
	}

}